<template>
  <view class="weather-card">
    <view class="header-actions">
      <view class="location" @click="handleChooseLocation">
        <text class="location-icon">📍</text>
        <text class="location-text">{{ location }}</text>
      </view>

      <view class="action-buttons">
        <view class="action-btn" @click="handleScreenshot">
          <text class="action-icon">📸</text>
        </view>
        <view class="action-btn" @click="handleRefresh">
          <text class="action-icon">🔄</text>
        </view>
      </view>
    </view>

    <view class="temperature-container">
      <view class="temperature">
        <text class="temp-num">{{ temperature }}</text>
        <text class="temp-unit">°C</text>
      </view>
    </view>

    <view class="weather-info">
      <view class="info-item">
        <text class="info-label">湿度</text>
        <text class="info-value">{{ humidity }}%</text>
      </view>
      <view class="info-item">
        <text class="info-label">风速</text>
        <text class="info-value">{{ windSpeed }}km/h</text>
      </view>
    </view>
  </view>
</template>

<script>
import { chooseLocation } from '@/utils/location'

export default {
  name: 'WeatherCard',
  props: {
    location: String,
    temperature: Number,
    humidity: Number,
    windSpeed: Number
  },
  emits: ['refresh', 'location-change', 'screenshot'],

  setup(props, { emit }) {
    const handleChooseLocation = async () => {
      try {
        const locationInfo = await chooseLocation()

        if (locationInfo && locationInfo.latitude && locationInfo.longitude) {
          emit('location-change', locationInfo)
        }
      } catch (error) {

      }
    }

    const handleRefresh = () => {
      emit('refresh')
    }

    const handleScreenshot = () => {
      emit('screenshot')
    }

    return {
      handleChooseLocation,
      handleRefresh,
      handleScreenshot
    }
  }
}
</script>

<style lang="scss">
.weather-card {
  background: rgba(255, 255, 255, 0.15);
  backdrop-filter: blur(20px);
  border-radius: 20px;
  padding: 16px;
  margin: 0;
  border: 1px solid rgba(255, 255, 255, 0.2);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);

  .header-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
  }

  .location {
    display: flex;
    align-items: center;
    transition: all 0.3s ease;

    &:active {
      transform: scale(0.95);
    }

    &-icon {
      font-size: 18px;
      filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.15));
    }

    &-text {
      font-size: 17px;
      color: #fff;
      margin-left: 8px;
      font-weight: 500;
      text-shadow: 0 2px 4px rgba(0, 0, 0, 0.15);
    }
  }

  .action-buttons {
    display: flex;
    gap: 10px;

    .action-btn {
      padding: 10px;
      border-radius: 50%;
      background: rgba(255, 255, 255, 0.18);
      backdrop-filter: blur(8px);
      transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
      box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);

      &:active {
        transform: scale(0.9);
        background: rgba(255, 255, 255, 0.28);
      }
    }

    .action-icon {
      font-size: 18px;
      filter: drop-shadow(0 1px 3px rgba(0, 0, 0, 0.15));
    }
  }

  .temperature-container {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    margin: 10px 0;
  }

  .temperature {
    font-size: 62px;
    color: #fff;
    text-align: center;
    font-weight: 600;
    text-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    letter-spacing: -2px;

    .temp-num {
      font-weight: 700;
    }

    .temp-unit {
      font-size: 24px;
      font-weight: 500;
      opacity: 0.9;
    }
  }

  .weather-info {
    display: flex;
    justify-content: space-around;
    margin-top: 14px;
    padding-top: 14px;
    border-top: 1px solid rgba(255, 255, 255, 0.15);

    .info-item {
      text-align: center;
      display: flex;
      flex-direction: column;
      gap: 6px;

      .info-label {
        font-size: 13px;
        color: rgba(255, 255, 255, 0.75);
        font-weight: 400;
      }

      .info-value {
        font-size: 16px;
        color: #fff;
        font-weight: 600;
        text-shadow: 0 2px 4px rgba(0, 0, 0, 0.15);
      }
    }
  }
}
</style>